package com.example.log4j2test.runner;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class LogRunner implements CommandLineRunner {
	public static final String SYS_APP_NAME = "sysAppName";
	public static final String SYS_APP_ADDRESS = "sysAppAddress";
	public static final String SYS_APP_VERSION = "sysAppVersion";
	public static final String SYS_APP_ZONE = "sysAppZone";
	
	@Autowired
	private Environment environment;
	
	@Override
	public void run(String... args) throws Exception {
		
		System.setProperty(SYS_APP_NAME, StringUtils.trimToEmpty(environment.getProperty("spring.application.name")));
		
		log.info("设置系统属性完成,{}={}", SYS_APP_NAME, System.getProperty(SYS_APP_NAME));
	}
	
}